<ui:composition xmlns="http://www.w3.org/1999/xhtml"
                xmlns:ui="http://java.sun.com/jsf/facelets"
                xmlns:h="http://java.sun.com/jsf/html"
                xmlns:f="http://java.sun.com/jsf/core"
                xmlns:p="http://primefaces.org/ui"
                template="../templates/ui.xhtml">
    
    <ui:define name="content">

        <h1 class="title ui-widget-header ui-corner-all">Dialog Framework - Data</h1>
        <div class="entry">
            <p>Dialog Framework provides features to pass and retrieve data between the source page and the dialog.</p>

            <h:form>

                <p:growl id="growl" showDetail="true" />
                
                <p:commandButton value="Select Car" icon="ui-icon-extlink" actionListener="#{dialogBean.chooseCar}">
                    <p:ajax event="dialogReturn" listener="#{dialogBean.onCarChosen}" update="growl" />
                </p:commandButton>

            </h:form>

            <h3>Source</h3>
            <p:tabView>
                <p:tab title="dialogFrameworkData.xhtml">
                    <pre name="code" class="xml">
&lt;h:form&gt;

    &lt;p:growl id="growl" showDetail="true" /&gt;

    &lt;p:commandButton value="Select Car" icon="ui-icon-extlink" actionListener="\#{dialogBean.chooseCar}"&gt;
        &lt;p:ajax event="dialogReturn" listener="\#{dialogBean.onCarChosen}" update="growl" /&gt;
    &lt;/p:commandButton&gt;

&lt;/h:form&gt;
                    </pre>
                </p:tab>
                
                <p:tab title="DialogBean.java">
                    <pre name="code" class="java">
public class DialogBean {
    
        public void chooseCar() {
            RequestContext.getCurrentInstance().openDialog("selectCar");
        }

        public void onCarChosen(SelectEvent event) {
            Car car = (Car) event.getObject();
            FacesMessage message = new FacesMessage(FacesMessage.SEVERITY_INFO, "Car Selected", "Model:" + car.getModel());

            FacesContext.getCurrentInstance().addMessage(null, message);
        }
}
                    </pre>
                </p:tab>
                
                <p:tab title="selectCar.xhtml">
                    <pre name="code" class="xml">
&lt;!DOCTYPE html&gt;
&lt;html xmlns="http://www.w3.org/1999/xhtml"
	xmlns:h="http://java.sun.com/jsf/html"
	xmlns:f="http://java.sun.com/jsf/core"
	xmlns:ui="http://java.sun.com/jsf/facelets"
    xmlns:p="http://primefaces.org/ui"&gt;
    
    &lt;h:head&gt;
        &lt;title&gt;Cars&lt;/title&gt;
        &lt;link type="text/css" rel="stylesheet" href="\#{request.contextPath}/css/default.css" /&gt;
    &lt;/h:head&gt;
    
    &lt;h:body&gt;
        &lt;h:form&gt;
            &lt;p:dataTable var="car" value="\#{tableBean.carsSmall}"&gt;
                &lt;p:column headerText="Model"&gt;
                    &lt;h:outputText value="\#{car.model}" /&gt;
                &lt;/p:column&gt;

                &lt;p:column headerText="Year"&gt;
                    &lt;h:outputText value="\#{car.year}" /&gt;
                &lt;/p:column&gt;

                &lt;p:column headerText="Manufacturer"&gt;
                    &lt;h:outputText value="\#{car.manufacturer}" /&gt;
                &lt;/p:column&gt;

                &lt;p:column headerText="Color"&gt;
                    &lt;h:outputText value="\#{car.color}" /&gt;
                &lt;/p:column&gt;

                &lt;p:column headerText="Color"&gt;
                    &lt;p:commandButton icon="ui-icon-search" actionListener="\#{tableBean.selectCarFromDialog(car)}" /&gt;
                &lt;/p:column&gt;
            &lt;/p:dataTable&gt;
        &lt;/h:form&gt;
    &lt;/h:body&gt;
    
&lt;/html&gt;
                    </pre>
                </p:tab>
                
                			<p:tab title="TableBean.java">
			<pre name="code" class="java">
package org.primefaces.examples.view;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
import java.util.UUID;

import org.primefaces.examples.domain.Car;

public class TableBean implements Serializable {
	
	static {
		colors = new String[10];
		colors[0] = "Black";
		colors[1] = "White";
		colors[2] = "Green";
		colors[3] = "Red";
		colors[4] = "Blue";
		colors[5] = "Orange";
		colors[6] = "Silver";
		colors[7] = "Yellow";
		colors[8] = "Brown";
		colors[9] = "Maroon";
		
		manufacturers = new String[10];
		manufacturers[0] = "Mercedes";
		manufacturers[1] = "BMW";
		manufacturers[2] = "Volvo";
		manufacturers[3] = "Audi";
		manufacturers[4] = "Renault";
		manufacturers[5] = "Opel";
		manufacturers[6] = "Volkswagen";
		manufacturers[7] = "Chrysler";
		manufacturers[8] = "Ferrari";
		manufacturers[9] = "Ford";
	}

    private final static String[] colors;

	private final static String[] manufacturers;
	
	private List&lt;Car&gt; carsSmall;
	
	public TableBean() {
		carsSmall = new ArrayList&lt;Car&gt;();
		
		populateRandomCars(carsSmall, 9);
	}
	
	private void populateRandomCars(List&lt;Car&gt; list, int size) {
		for(int i = 0 ; i &lt; size ; i++)
			list.add(new Car(getRandomModel(), getRandomYear(), getRandomManufacturer(), getRandomColor()));
	}
	
	public List&lt;Car&gt; getCarsSmall() {
		return carsSmall;
	}

	private int getRandomYear() {
		return (int) (Math.random() * 50 + 1960);
	}
	
	private String getRandomColor() {
		return colors[(int) (Math.random() * 10)];
	}
	
	private String getRandomManufacturer() {
		return manufacturers[(int) (Math.random() * 10)];
	}
	
	private String getRandomModel() {
		return UUID.randomUUID().toString().substring(0, 8);
	}

    public void selectCarFromDialog(Car car) {
        RequestContext.getCurrentInstance().closeDialog(car);
    }
}
				</pre>
			</p:tab>

                
            </p:tabView>

        </div>

    </ui:define>
</ui:composition>